﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.Manage.SqlServerDAL;

public partial class DataBase_ParamManage : Baimasoft.Web.UI.PageManagerTop
{
    Param MyP = new Param();
    ParamType MyPT = new ParamType();

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            Indicator.Text = Request.QueryString["sIndicator"].ToString();
        }
        catch
        {
        }

        this.BindControlEvent();

        this.HiddenID.Value = "";
        if (!this.IsPostBack)
        {
            ParamTypeDataBind();
            this.BindGridViewData();
        }
    }

    protected override void BindGridViewData()
    {
        this.DataSource = MyP.GetParams (GetSearchString());
        this.DataSource.DefaultView.Sort = this.SortString;
        GridView1.DataSource = this.DataSource.DefaultView;
        GridView1.DataBind();
    }

    public void ParamTypeDataBind()
    {
        ParamType.DataSource = MyPT.GetParamTypes (" status='1' ");
        ParamType.DataBind();
        ParamType.Items.Insert(0, "全部类别");
        ParamType.Items[0].Value = "";
    }


    protected override void Delete(string ids)
    {
        try
        {
            int iback = MyP .DeleteParam (ids);
            if (iback < 1)
            {
                Baimasoft.Web.UI.Message.AlertMsg(this, "没有可删除的数据");
                return;
            }
            else
            {
                Baimasoft.Web.UI.Message.AlertMsg(this, "删除成功");
                return;
            }
        }
        catch
        {
            Baimasoft.Web.UI.Message.AlertMsg(this, "删除失败");
            return;
        }
    }

    protected override string GetSearchString()
    {
        string searchStr = string.Empty;

        string sName = Name.Text.ToString().Trim();
        string sCode = ParamType.SelectedValue.ToString().Trim();

        searchStr += " (1=1) ";

        if (sName != "")
        {
            searchStr += " and  a.Name like'%" + sName + "%' ";
        }

        if (sCode != "" )
        {
            searchStr += " and  b.code = '" + sCode + "' ";
        }


        return searchStr;
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        this.DataSource = MyP .GetParams (GetSearchString());
        this.DataSource.DefaultView.Sort = this.SortString;
        GridView1.DataSource = this.DataSource.DefaultView;
        GridView1.DataBind();
    }
}
